package com.mazaiting.mybatisplus.domain.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.io.Serializable;
import java.util.List;

/**
 * 分页返回所需要的值
 */
public class BasePageVO<T> implements Serializable {

    /**
     * 当前页
     */
    private Long page;
    /**
     * limit 每页大小
     */
    private Long size;
    /**
     * 总条数
     */
    private Long total;
    /**
     * 总页数
     */
    private Long pages;
    /**
     * 返回列表
     */
    private List<T> list;

    /**
     * 成功返回
     * @param page 页面数据
     * @return 分页基类
     * @param <T> 泛型
     */
    public static <T> BasePageVO<T> success(IPage<T> page) {
        BasePageVO<T> basePageVO = new BasePageVO<>();
        basePageVO.setTotal(page.getTotal());
        basePageVO.setList(page.getRecords());
        return basePageVO;
    }

    public Long getPage() {
        return page;
    }

    public void setPage(Long page) {
        this.page = page;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public Long getTotal() {
        return this.total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Long getPages() {
        return pages;
    }

    public void setPages(Long pages) {
        this.pages = pages;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
